﻿/*
    Project: IV:MP GUI Editor (http://code.google.com/p/ivmp-gui-editor)
    Code license: GNU Lesser GPL (http://www.gnu.org/copyleft/lesser.html) 
 */

using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
namespace IvmpEditor
{
    public class GUIText : GUIElement
    {
        public new const string TYPE = "GUIText";
        public override string GetTypeName() { return TYPE; }
        public override string GetDefaultVarName() { return "label"; }
        private new Label nativeControl;
        public new Label NativeControl { get { return this.nativeControl; } }

        public GUIText(string _variableName)
        {
            variableName = _variableName;
            properties = new Dictionary<string, object>(25);
            MakeControl();
        }
        protected override void MakeControl()
        {
            // Create a native control of Text stylized with CEGUI_Text
            nativeControl = new Label();
            base.nativeControl = this.nativeControl;
            moveControlAgent = new WpfMoveControlAgent(nativeControl);

            nativeControl.Style = GetBaseStyle();
            SetControlFont(nativeControl, "#tahoma-bold", 12, FontWeights.Black);
            nativeControl.Content = variableName;
        }
        public override void InstallMoveControlAgent()
        {
            // Because Label control has problems with normal capturing events only from itself:
            moveControlAgent.InstallTo(
                new FrameworkElement[]
                { 
                    nativeControl, 
                    GetParent().Workbench as FrameworkElement
                });
        }
        public override void SetText(string newTxt, bool native)
        {
            base.SetText(newTxt, native);
            if (native && nativeControl != null)
                nativeControl.Content = newTxt;
        }
        public override void SyncFromNative()
        {
            base.SyncFromNative();
        }
        public override void SyncToNative()
        {
            base.SyncToNative();
        }
        public override string GetSQCode(ref SquirrelCodeStack sq)
        {
            sq.wSet(null, variableName, TYPE + "()", true);

            WriteElementCommonCode(ref sq, new Point(2.1, -0.5), variableName);

            return variableName;
        }
        public override Style GetBaseStyle()
        {
            return App.Current.FindResource("CEGUI_Text") as Style;
        }
    }
}
